package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.SysPtExpVo;
import com.ruoyi.system.bo.SysPtExpQueryBo;
import com.ruoyi.system.bo.SysPtExpAddBo;
import com.ruoyi.system.bo.SysPtExpEditBo;
import com.ruoyi.system.service.ISysPtExpService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 实验管理Controller
 *
 * @author 莫修
 * @date 2021-11-28
 */
@Api(value = "实验管理控制器", tags = {"实验管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/SysExp")
public class SysPtExpController extends BaseController {

    private final ISysPtExpService iSysPtExpService;

    /**
     * 查询实验管理列表
     */
    @ApiOperation("查询实验管理列表")
    @PreAuthorize("@ss.hasPermi('system:SysExp:list')")
    @GetMapping("/list")
    public TableDataInfo<SysPtExpVo> list(@Validated SysPtExpQueryBo bo) {
        return iSysPtExpService.queryPageList(bo);
    }

    /**
     * 导出实验管理列表
     */
    @ApiOperation("导出实验管理列表")
    @PreAuthorize("@ss.hasPermi('system:SysExp:export')")
    @Log(title = "实验管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<SysPtExpVo> export(@Validated SysPtExpQueryBo bo) {
        List<SysPtExpVo> list = iSysPtExpService.queryList(bo);
        ExcelUtil<SysPtExpVo> util = new ExcelUtil<SysPtExpVo>(SysPtExpVo.class);
        return util.exportExcel(list, "实验管理");
    }

    /**
     * 获取实验管理详细信息
     */
    @ApiOperation("获取实验管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:SysExp:query')")
    @GetMapping("/{expId}")
    public AjaxResult<SysPtExpVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("expId") Long expId) {
        return AjaxResult.success(iSysPtExpService.queryById(expId));
    }

    /**
     * 新增实验管理
     */
    @ApiOperation("新增实验管理")
    @PreAuthorize("@ss.hasPermi('system:SysExp:add')")
    @Log(title = "实验管理", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody SysPtExpAddBo bo) {
        return toAjax(iSysPtExpService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改实验管理
     */
    @ApiOperation("修改实验管理")
    @PreAuthorize("@ss.hasPermi('system:SysExp:edit')")
    @Log(title = "实验管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody SysPtExpEditBo bo) {
        return toAjax(iSysPtExpService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除实验管理
     */
    @ApiOperation("删除实验管理")
    @PreAuthorize("@ss.hasPermi('system:SysExp:remove')")
    @Log(title = "实验管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{expIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] expIds) {
        return toAjax(iSysPtExpService.deleteWithValidByIds(Arrays.asList(expIds), true) ? 1 : 0);
    }
}
